$(function () {
    // 初始化主体结构交换
    interactiveInit();
    window.onresize = interactiveInit;
    setTimeout(() => {
        // 展示导航栏
        // $(".container .navigation_bar").css({ opacity: "1" });
        $(".container .content .card.card_1 .loading .logo").css({
            opacity: "1"
        })
        $(".container .content .card.card_1 .loading .line").css({
            opacity: "1",
            width: "50vw"
        })
        $(".container .content .card.card_1 .loading .schedule").text("100%").css({
            opacity: "1"
        })
    }, 1500);
})

function moveCardInit() {
    const contentJQ = $(".content");
    const cardHeight = $(".card").height();
    console.log("cardHeight", cardHeight)
    function move(index) {
        $("[index=" + index + "]").addClass("active").siblings().removeClass("active");
        contentJQ.css({ transform: `translateY(${-1 * index * cardHeight}px)` })
    }
    return function (index) {
        move(index)
    }
}

function interactiveInit() {
    const moveCard = moveCardInit();
    let currentIndex = 0;
    moveCard(0);
    $(".navigation").off("click");
    $(".navigation").on("click", function (ev) {
        currentIndex = parseInt($(this).attr("index"));
        moveCard(currentIndex);
    })
    const documentElement = $(document.documentElement);
    let lock = true;
    documentElement.off("mousewheel");
    documentElement.on("mousewheel", function (ev) {
        if (ev.originalEvent.wheelDeltaY < -15 && lock) {
            lock = false;
            setTimeout(function () {
                lock = true
            }, 1000);
            if (currentIndex + 1 <= 3) {
                currentIndex++;
                moveCard(currentIndex);
            }
        } else if (ev.originalEvent.wheelDeltaY > 15 && lock) {
            lock = false;
            setTimeout(function () {
                lock = true
            }, 1000);
            if (currentIndex - 1 >= 0) {
                currentIndex--;
                moveCard(currentIndex);
            }
        }
    });
    let touchStartY = 0;
    let touchEndY = 0;
    documentElement.off("touchstart");
    documentElement.on("touchstart", function (ev) {
        touchStartY = ev.originalEvent.changedTouches[0].clientY;
    })
    documentElement.off("touchend");
    documentElement.on("touchend", function (ev) {
        touchEndY = ev.originalEvent.changedTouches[0].clientY;
        if (touchEndY - touchStartY < -15 && lock) {
            console.log("下一页");
            lock = false;
            setTimeout(function () {
                lock = true
            }, 1000);
            if (currentIndex + 1 <= 3) {
                currentIndex++;
                moveCard(currentIndex);
            }
        } else if (touchEndY - touchStartY > 15 && lock) {
            console.log("上一页")
            lock = false;
            setTimeout(function () {
                lock = true
            }, 1000);
            if (currentIndex - 1 >= 0) {
                currentIndex--;
                moveCard(currentIndex);
            }
        }
    })
}